package com.suredy.app.porject._init;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.suredy.app.porject.constants.MoneyType;
import com.suredy.app.porject.service.ProjectConstants;
import com.suredy.core.service.DictionarySrv;

/**
 * 初始化系统参数
 * 
 * @author VIVID.G
 * @since 2015-11-6
 * @version v0.1
 */
@Component
public class ProjectInit {

	@Autowired
	private DictionarySrv dictionarySrv;

	@PostConstruct
	protected void init() {
		this.initBidPayoutNames();

		this.initContractPayoutNames();

		this.initBidQuotationType();

		this.initContractBusinessType();

		this.initBidType();

		this.initBidWay();

		this.initContractJiesuanWay();

		this.initDoContractCompany();
	}

	private void initBidPayoutNames() {
		List<String> values = new ArrayList<String>();

		for (MoneyType mt : MoneyType.FOR_BID_PAYOUT) {
			values.add(mt.getValue());
		}

		this.initDictionary(ProjectConstants.DK_BID_PAYOUT_NAME, values.toArray(new String[values.size()]), true);
	}

	private void initContractPayoutNames() {
		List<String> values = new ArrayList<String>();

		for (MoneyType mt : MoneyType.FOR_CONTRACT_PAYOUT) {
			values.add(mt.getValue());
		}

		this.initDictionary(ProjectConstants.DK_CONTRACT_PAYOUT_NAME, values.toArray(new String[values.size()]), true);
	}

	private void initBidQuotationType() {
		String[] values = new String[] {"总价", "单价", "降点"};

		this.initDictionary(ProjectConstants.DK_BID_QUOTATION_TYPE, values, true);
	}

	private void initContractBusinessType() {
		String[] values = new String[] {"电网基建类", "电网生产类", "运维抢修类", "营销辅助类", "非电网客户类", "EPC总承包项目类", "租赁业务类", "水电站类", "物资采购类", "其他类"};

		this.initDictionary(ProjectConstants.DK_CONTRACT_BUSINESS_TYPE, values, true);
	}

	private void initBidType() {
		String[] values = new String[] {"工程", "物资", "服务"};

		this.initDictionary(ProjectConstants.DK_BID_TYPE, values, true);
	}

	private void initBidWay() {
		String[] values = new String[] {"公开招标", "竞争性谈判", "单一来源", "询价（报价）"};

		this.initDictionary(ProjectConstants.DK_BID_WAY, values, true);
	}

	private void initContractJiesuanWay() {
		String[] values = new String[] {"固定（包干）价结算", "按甲方最终审定批复价结算（含降点）", "按实际完成工程量据实结算", "按第三方最终审定价结算（含降点）"};

		this.initDictionary(ProjectConstants.DK_CONTRACT_JIESUAN_WAY, values, true);
	}

	private void initDoContractCompany() {
		String[] values = new String[] {"送电分公司", "变电分公司", "配网运检分公司", "带电作业分公司", "发电分公司", "云南广众工程咨询有限公司", "云南红河电力设计有限公司", "红河万祥物业服务有限公司", "红河汇达物流有限公司", "云南天星实业有限公司文化城"};

		this.initDictionary(ProjectConstants.DK_DO_CONTRACT_COMPANY, values, true);
	}

	private void initDictionary(String dicGroup, String[] values, boolean system) {
		this.dictionarySrv.addIfNotExists(dicGroup, values, system);
	}

}
